package cn.xopencode.oss.rpc.permission;

import cn.xopencode.common.framework.vo.CommonResult;
import cn.xopencode.oss.dal.redis.dao.OAuth2UserPositionPemissionDAO;
import cn.xopencode.oss.manager.permission.PermissionManager;
import cn.xopencode.oss.rpc.permission.dto.PermissionAssignEmployeePositionDTO;
import cn.xopencode.oss.rpc.permission.dto.PermissionAssignPositionResourceDTO;
import cn.xopencode.oss.rpc.permission.dto.PermissionCheckDTO;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Set;

import static cn.xopencode.common.framework.vo.CommonResult.success;

/**
 * 权限 Rpc 实现类
 */
@DubboService(version = "${dubbo.provider.PermissionRpc.version}")
public class PermissionRpcImpl implements PermissionRpc {

    @Autowired
    private PermissionManager permissionManager;
    @Autowired
    private OAuth2UserPositionPemissionDAO oAuth2UserPositionPemissionDAO;
    @Override
    public CommonResult<Set<String>> listPositionResourceIds(String positionId) {
        return success(permissionManager.listPositionResourceIds(positionId));
    }

    @Override
    public CommonResult<Boolean> assignPositionResource(PermissionAssignPositionResourceDTO assignPositionResourceDTO) {
        permissionManager.assignPositionResource(assignPositionResourceDTO);
        return success(true);
    }

    @Override
    public CommonResult<Boolean> assignEmployeeRole(PermissionAssignEmployeePositionDTO assignEmployeePositionDTODTO) {
        permissionManager.assignEmployeePosition(assignEmployeePositionDTODTO);
        return success(true);
    }


    @Override
    public CommonResult<Boolean> checkPermission(PermissionCheckDTO checkDTO) {
        permissionManager.checkPermission(checkDTO);
        return success(true);
    }

    @Override
    public PermissionCheckDTO get(String userID) {
        return oAuth2UserPositionPemissionDAO.get(userID);
    }

    @Override
    public void set(PermissionCheckDTO permissionCheckDO) {
        oAuth2UserPositionPemissionDAO.set(permissionCheckDO);
    }

}
